<template>
  <div>
    <div class="pic"></div>
    <a href="#" class="top" v-show="gotop">
      <div class="shang">↑</div>
    </a>
  </div>
</template>

<script>
export default {
  data() {
    return {
      gotop: false,
    };
  },
  methods: {
    handleScroll() {
      let scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      if (scrollTop > 200) {
        this.gotop = true;
      } else if (scrollTop < 200) {
        this.gotop = false;
      }
    },
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
};
</script>

<style scoped>
.pic {
  width: 100%;
}
.pic img {
  display: block;
  width: 100%;
}
.top {
  
  width: 10vw;
  height: 10vw;
  border-radius: 50%;
  text-align: center;
  background-color: rgba(201, 201, 201, 0.651);
  color: #fff;
  /*固定定位 是相对浏览器窗口可显示区域的定位，不管写在哪里，都参照窗口定位*/
  position: fixed;
  /*层级顺序*/
  z-index: 10;
  bottom: 10vh;
  right: 6vw;
}
.shang {
  margin-top: 7px;
  font-size: 1.2em;
  color: rgba(136, 136, 136, 0.74);
}
</style>
